package algebra;

import java.text.DecimalFormat;

public class Poly {

	char variable;
	double coefficient;
	int degree;
	char prevOp;
	
	public Poly(char v, int d, double c){
		variable = v;
		degree = d;
		coefficient = c;
	}
	
	public String toString(){
		DecimalFormat df = new DecimalFormat("#.###");
		if(coefficient == 1){
			if(degree == 1){
				if(variable == '\0'){
					return ""+df.format(coefficient);
				}else{
					return ""+variable;
				}
			}
			return ""+variable+"^"+degree;
		}
		if(coefficient == -1){
			if(degree == 1){
				if(variable == '\0'){
					return ""+df.format(coefficient);
				}else{
					return "-"+variable;
				}
			}
			return "-"+variable+"^"+degree;
		}
		if(degree == 1){
			if(variable == '\0'){
				return df.format(coefficient);
			}
			return ""+df.format(coefficient)+""+variable;
		}
		return ""+df.format(coefficient)+"("+variable+"^"+degree+")";
	}
	
}
